﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Toulr.Util.Ioc;
using Toulr.Services;
using Toulr.Models.Account;
using Toulr.Models;

public partial class Account_Reg2 : CommPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string email = ViewState["email"].ToString();
            if (txtEmail.Value != email)
            {
                PageHelper.Go2Error("您的浏览器客户端非法修改了偷乐网上的数据！");
                AddClientErrorMessageBox(null, "您输入的Email地址不正确!");
                return;
            }

            IUserContextService iUser = UnityHelper.GetInstance<IUserContextService>();
            RegisterModel model = new RegisterModel(email, txtPwd.Value, txtRealName.Value);

            ActionResult<bool> result = iUser.Register(model);
            if (result.Result)
            {
                Server.Transfer("RegisterSuccess.aspx?email=" + Uri.EscapeDataString(email));
            }
            else
            {
                AddClientErrorMessageBox("注册失败", "详细原因如下：<br><b>" + result.Tips + "</b>");
            }
        }

        else
        {
            string emailCode = Request["i"];
            string timeCode = Request["t"];

            IUserContextService iUser = UnityHelper.GetInstance<IUserContextService>();
            ActionResult<string> actionResult = iUser.VerifyEmailLink(emailCode, timeCode);
            if (actionResult.ResultCode == 0)
            {
                //成功
                txtEmail.Value = actionResult.Result;
                ViewState["email"] = actionResult.Result;
            }
            else
            {
                PageHelper.Go2Error(actionResult.Tips);
                return;
            }
        }
    }
}
